<template>
  <div>
    <!--    <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">-->
    <!--      <el-radio-button :label="false">展开</el-radio-button>-->
    <!--      <el-radio-button :label="true">收起</el-radio-button>-->
    <!--    </el-radio-group>-->

    <el-menu
      router
      :default-active="this.$route.fullPath"
      class="el-menu-vertical-demo"
      :collapse="this.$store.state.user.flod"
      background-color="#545c64"
      text-color="#fff">
      <div class="layout-logo">
        <img src="../../assets/logo.png">
        <span>智币精灵</span>
      </div>
      <div v-if="!r.meta.hidden" v-for="r in myRoutes" :key="r.path">
        <!--        <el-menu-item  :index="r.path=='/'?'/homeView':r.path"  v-if="isOnlyOneChild(r.children)">-->
        <el-menu-item :index="r.path=='/'?'/homeView':r.path"
                      v-if="isOnlyOneChild(r.children) && r.userType.includes(type)">
          <i :class="r.meta.elIcon"></i>
          {{ r.meta.title }}
        </el-menu-item>
        <el-submenu v-if="!isOnlyOneChild(r.children)">
          <template slot="title">
            <i :class="r.meta.elIcon"></i>
            <span>{{ r.meta.title }}</span>
          </template>
          <el-menu-item :index="innerR.path" v-for="innerR in r.children" :key="innerR.path">
            <i :class="innerR.meta.elIcon"></i>
            <span slot="title">{{ innerR.meta.title }}</span>
          </el-menu-item>
        </el-submenu>
      </div>
    </el-menu>

  </div>
</template>
<script>
export default {
  name: "index",
  data() {
    return {
      type: localStorage.getItem('userType'),
      myRoutes: this.$router.options.routes
    };
  },
  mounted() {
    this.isOnlyOneChild()
  },
  methods: {
    isOnlyOneChild(children) {
      return children.length === 1
    },
  }
}
</script>

<style scoped lang="scss">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu-item.is-active {
  background-color: #000000 !important;
  color: #409eff;

  * {
    background-color: #000000 !important;
    color: #409eff;
  }
}
.layout-logo {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;

  img {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    margin-right: 5px;
  }

  span {
    color: #1c84c6;
    white-space: nowrap;
    display: inline-block;
    //color: var(--el-color-primary);
    font-size: 16px;
    cursor: pointer;
    letter-spacing: 1px;
    margin-left: 8px;
  }
}

//.aside {
//  width: 100%;
//  height: 100%;
//}

h4 {
  display: flex;
  align-items: center;
  justify-content: center;

  .logo {
    width: 40px;
    height: 40px;
    margin-right: 10px;
    border-radius: 4px;
  }
}

.el-menu {
  border-right: 0;
  height: 100%;
}
</style>
